local eyao = fk.CreateSkill({
    name = "sj6__eyao",
})

Fk:loadTranslationTable{
  ["sj6__eyao"] = "扼要",
  [":sj6__eyao"] = "出牌阶段开始时或当一名角色使用装备牌后，若场上的装备数之和为：奇数，你可以摸一张牌；偶数，你可以展示一名角色的一张手牌，本回合该角色与此牌同名的手牌均视为【过河拆桥】。",

  ["@$sj6__eyao-turn"] = "扼要",
  ["#sj6__eyao-ji"] = "扼要：你可以摸一张牌",
  ["#sj6__eyao-ou"] = "扼要：你可以展示一名角色的一张手牌，令其同名手牌视为【过河拆桥】",
  ["#sj6__eyao-ask"] = "扼要：请选择一名角色",

  ["$sj6__eyao1"] = "将者临战，谋先定而后动兵戈。",
  ["$sj6__eyao2"] = "沙场交兵，先击未中者命悬矣。",
}

local eyao_spec = {
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      return player:hasSkill(eyao.name) and data.card.type == Card.TypeEquip and not player.dead
    else
      return target == player and player:hasSkill(eyao.name) and player.phase == Player.Play--出牌开始
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local i = 0
    for _, p in ipairs(player.room:getAlivePlayers()) do
      i = i + #p:getCardIds("e")
    end
    i = i % 2
    event:setCostData(self,{num = i})
    if i == 0 then
      local ps = room:askToChoosePlayers(player,{
        targets = table.filter(room:getAlivePlayers(),function (p) return #p:getCardIds("h") > 0 end),
        min_num = 1,
        max_num = 1,
        prompt = "#sj6__eyao-ou",
        skill_name = eyao.name
      })
      if #ps > 0 then
        event:setCostData(self,{num = i, p = ps[1]})
        return true
      end
    else
      return room:askToSkillInvoke(player,{skill_name = eyao.name,prompt = "#sj6__eyao-ji"})
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cost = event:getCostData(self)
    if cost.num == 0 then
      local p = cost.p
      local c = Fk:getCardById(room:askToChooseCard(player,{
        target = p,
        flag = "h",
        skill_name = eyao.name,
      }))
      p:showCards(c)
      room:addTableMarkIfNeed(p,"@$sj6__eyao-turn",c.trueName)
    else
      room:drawCards(player,1,eyao.name)
    end
  end,
}

eyao:addEffect(fk.EventPhaseStart,eyao_spec)
eyao:addEffect(fk.CardUseFinished,eyao_spec )

eyao:addEffect("filter", {
  anim_type = "control",
  card_filter = function(self, card, player)
    return table.contains(player:getTableMark("@$sj6__eyao-turn"),card.trueName)
  end,
  view_as = function(self, player, card)
    local c = Fk:cloneCard("dismantlement", card.suit, card.number)
    c.skillName = eyao.name
    return c
  end,
})

return eyao